%% @author Rain
%% @doc 玩家客户端进程接口


-module(player_svr_util).

-include("proto.hrl").
-include("pb_account.hrl").

%% ====================================================================
%% API functions
%% ====================================================================
-export([player_send_msg/2,
		 send_msg/3,
		 start_link/1]).



%% ====================================================================
%% Internal functions
%% ====================================================================

%% @doc 玩家发送消息给服务端
player_send_msg(MsgId, Msg) ->
	player_svr ! {send_msg, MsgId, Msg}.

%% @doc 玩家进程调用，发送tcp消息
send_msg(MsgId, Msg, Sock) ->
	BinMsg = util_msg:encode_msg(MsgId, Msg),
	case gen_tcp:send(Sock, BinMsg) of
		ok ->
			io:format("Send MsgId:~p Msg ~p~n", [MsgId, Msg]),
			ok;
		{error, Reason} ->
			io:format("Send MsgId:~p Msg ~p Fail, Please Check Connection~n~n", [MsgId, Msg]),
			io:format("Reason: ~p~n",[Reason]),
			error
	end.

start_link(Args) ->
	gen_server:start_link({local, player_svr}, player_svr, Args, []).
	